﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class User_projectcount : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["tid"] != null)
            {
                //处理日期
                int year = DateTime.Now.Year;
                this.ddlYear.Items.Add(new ListItem(year.ToString() + "—" + (year - 4).ToString(), year.ToString()));
                this.ddlYear.Items.Add(new ListItem((year - 5).ToString() + "—" + (year - 9).ToString(), (year - 5).ToString()));
                this.ddlYear.Items.Add(new ListItem((year - 10).ToString() + "—" + (year - 14).ToString(), (year - 10).ToString()));
                this.ddlYear.Items.Add(new ListItem((year - 15).ToString() + "—" + (year - 19).ToString(), (year - 15).ToString()));
                GetData(Session["tid"].ToString(), year);
            }
            else
                Response.Redirect("../Error/Error.htm");
        }
    }
    //进度信息处理
    static public string strStatus(string status)
    {
        //0待填1待初审2待终审3待中期检查4待结题5已结题10取消11延期20初审退回待填21终审退回待初审30删除标记
        if (status == "1")
            return "待初审";
        if (status == "2")
            return "待终审";
        if (status == "3")
            return "待中期检查";
        if (status == "4")
            return "待结题";
        if (status == "5")
            return "已结题";
        if (status == "11")
            return "延期";
        if (status == "20")
            return "初审退回";
        if (status == "21")
            return "终审退回";
        else
            return "无";
    }
    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Session["tid"] != null)
        {
            GetData(Session["tid"].ToString(), Int16.Parse(this.ddlYear.SelectedValue));
        }
        else
            Response.Redirect("../Error/Error.htm");
    }
    protected void GetData(string tid, int nowyear)
    {
        StringBuilder sqlstr = new StringBuilder("select id,[type],pname,plevel,ptype,status,year(builddate)  as [year],builddate from View_Projects");
        sqlstr.Append(" where tid='").Append(tid).Append("' and year(builddate)<=").Append(nowyear).Append(" and year(builddate)>").Append(nowyear - 5);
        DataTable dt = PM.Code.DAL.DbHelper.ExecuteDataTableBySql(sqlstr.ToString());
        RProjectCount.DataSource = dt;
        RProjectCount.DataBind();

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["tid"] == null)
            Response.Redirect("../Error/Error.htm");
        string tid = Session["tid"].ToString();
        StringBuilder sqlstr = new StringBuilder("select year(builddate)  as 年度, [type] as 申报类型,pname as 项目名称,plevel as 项目级别,ptype as 项目类型,status as 状态,builddate as 日期 from View_Projects");
        sqlstr.Append(" where tid='").Append(tid).Append("'");
        DataTable mytable = PM.Code.DAL.DbHelper.ExecuteDataTableBySql(sqlstr.ToString());
        PM.Code.Web.output.DataTableToExcel(mytable, "个人申报项目统计表");
    }
}

